package logic

import (
	"api/model/mysql"
	"context"
	"house_srv/house"
	"house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLogic {
	return &AddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddLogic) Add(in *house.AddRequest) (*house.AddResponse, error) {
	// todo: add your logic here and delete this line

	m := mysql.House{
		HouseCity:    in.HouseCity,
		HouseAddress: in.HouseAddress,
		HouseNumber:  in.HouseNumber,
		HouseFloor:   in.HouseFloor,
		HouseArea:    int(in.HouseArea),
		HousePrice:   float64(in.HousePrice),
		HouseStatus:  1,
	}

	mysql.DB.Create(&m)

	return &house.AddResponse{
		Id: int64(m.ID),
	}, nil
}
